<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
//    角色扮演类游戏里，角色有很多种，比如法师、战士等
//    首先创建一个类
    var klass = (function () {
        var F = function () {
        };

        return function (Parent) {
            var Child;

            Child = function () {
                Child.superproto.constructor.apply(this, arguments);
            };

            F.prototype = Parent.prototype;
            Child.prototype = new F();
            Child.prototype.constructor = Child;
            Child.superproto = Parent.prototype;

            return Child;
        };
    })();

    var Character = function () {}, Warrior = klass(Character), Mage = klass(Character), Archer = klass(Character), Player = function () {};

    Character.prototype.level = function () {
    };
    Character.prototype.gather = function () {
    };
    Character.prototype.fight = function () {
    };

    Player.prototype.play = function (role) {
        var character;
        switch (role) {
            case "战士":
                character = new Warrior();
                break;
            case "法师":
                character = new Mage();
                break;
            case "弓箭手":
                character = new Archer();
                break;
            default:
                character = new Warrior();
        }
        character.level();
        character.gather();
        character.fight();
    };

    var fashi = new Player();
    fashi.play("法师");

    var fighter = new Player();
    fighter.play('战士');
</script>
</body>
</html>